package servlet.manager;

import service.manager.ReturnService;
import service.manager.impl.ReturnServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * ReturnServlet
 *
 * @author ChenYanMei
 * @version 2023/9/1
 */
@WebServlet("/ReturnServlet")
public class ReturnServlet extends HttpServlet {
    // 引入Service层
    ReturnService service = new ReturnServiceImpl();

    /**
     * doGet()提交
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    /**
     * doPost（）提交
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置编码
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/JSON;charset=utf-8");
        resp.setCharacterEncoding("UTF-8");

        // 创建输出对象
        PrintWriter out = resp.getWriter();

        HttpSession session = req.getSession();
        String  book = session.getAttribute("book").toString();
        int days = service.overDate(Integer.valueOf(book));// 获取逾期天数
       session.setAttribute("days", days);

       resp.sendRedirect("manager/04return.jsp");
       return;
    }
}
